﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using ShortLink.Common.Jwt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShortLink.Common
{
    public class App
    {
        public static IServiceProvider serviceProvider;
        public App(IServiceProvider provider) 
        {
            serviceProvider = provider;
        }

        public static TokenModel GetUser() 
        {
            var acc = serviceProvider.GetService<IHttpContextAccessor>();
            var token = acc.HttpContext.Request.Headers["Authorization"].ToString();
            token = token.Replace("Bearer ", "");
            return JwtHelper.ParseTokenModel(token);

        }
    }
}
